class Ball{
  int diameter;
  PVector location;
  PVector velocity;
  PVector acceleration;
  
  Ball(){
    diameter = 40;
    location = new PVector(0 + (diameter / 2), height - (diameter / 2));
    velocity = new PVector(0, 0);
    acceleration = new PVector(0, 0);
  }
  
  // Move the ball by using vectors
  void move(){
    location.add(velocity);
    velocity.add(acceleration);
    
    if (velocity.x < 0.005){
      velocity.mult(0);
    }

    acceleration.mult(0);
  }
  
  // Draw the ball
  void display(){
    fill(255);
    noStroke();
    
    circle(location.x, location.y, diameter);
  }
  
  // Stop the ball when it reaches the edge of the screen
  void edgeStop(){
    if (location.x + (diameter / 2) >= width){
      velocity.setMag(0); 
    }
  }
  
  // Change acceleration by a given force (Used to add friction)
  void applyForce(PVector force){
    acceleration.add(force);
  }
  
  // Calculate the friction force, based on the coefficient of friction
  PVector applyFriction(float frictionForce){
    PVector friction = velocity.copy();
    friction.normalize().mult(-1).mult(frictionForce);
    return friction;
  }
  
  // Let the ball start rolling when the button is pressed
  void startRoll(){
    location = new PVector(0 + (diameter / 2), height - (diameter / 2));
    velocity = new PVector(5, 0);
  }
  
  // Draw the "Start Rolling" button and let it call startRoll() if pressed
  void displayStartButton(){
    stroke(255);
    strokeWeight(3);
    fill(0);
    rect(20, 50, 125, 30);
    
    textAlign(LEFT, CENTER);
    textSize(16);
    fill(255);
    text("Start Rolling", 35, 65);
    
    if (mouseX > 20 && mouseX < 145 && mouseY > 50 && mouseY < 80){
      cursor(HAND);
      if (mousePressed){
        startRoll();
      }
    } else{
      cursor(ARROW);
    }
  }
}
